package com.doit.mr.day03;

import java.io.*;

/**
 * @DATE 2021/12/8/20:37
 * @Author MDK
 * @Version 2021.2.2
 * jdk的序列化机制  将数据转化成二进制的过程添加了一些类的信息  不利于大量数据网络传输
 **/
public class TestUser {
    public static void main(String[] args) throws Exception {
        User user = new User(1,"zss",23);
        //将user持久化到磁盘上
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("d://aaa//1.txt"));
//        oos.writeObject(user);
//        //反序列化
//        oos.writeInt(user.getId());
//        oos.writeUTF(user.getName());
//        oos.writeInt(user.getAge());

        //反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("d://aaa//1.txt"));
        int id = ois.readInt();
        String name = ois.readUTF();
        int age = ois.readInt();
        System.out.println(name);

        ois.close();
    }
}
